import { http } from "../http";
import {
  mockPublishNotify,
  mockGetNotifyList,
  mockAddMessage,
  mockProcessMessage,
} from "../mock/systemNotify";

const baseUrl = "/api/dms/systemNotify";

// 控制是否使用Mock API的全局变量
const USE_MOCK = true; // 设置为 true 使用Mock，false 使用真实API

// 消息类型
export interface PublishNotifyType {
  id: string;
  type?: string;
  content: string;
  createTime?: string;
  status?: string;
}

// 消息列表查询参数
export interface GetNotifyListQueryType {
  currentPage: number | null;
  numPerPage: number | null;
}

// 添加消息参数
export interface AddMessageType {
  type: string;
  content: string;
  priority?: string;
}

// 处理消息参数
export interface ProcessMessageType {
  id: string;
  status: string;
  remark?: string;
}

// 消息列表
export const getNotifyListAPI = (params: GetNotifyListQueryType) => {
  if (USE_MOCK) {
    return mockGetNotifyList(params).then((data) => data.data);
  }
  return http.post(`${baseUrl}/getNotifyList`, params);
};

// 发布消息
export const publishNotifyAPI = (params: PublishNotifyType) => {
  if (USE_MOCK) {
    return mockPublishNotify(params).then((data) => data.data);
  }
  return http.post(`${baseUrl}/publishNotify`, params);
};

// 添加系统消息
export const addMessageAPI = (params: AddMessageType) => {
  if (USE_MOCK) {
    return mockAddMessage(params).then((data) => data.data);
  }
  return http.post(`${baseUrl}/addMessage`, params);
};

// 处理系统消息
export const processMessageAPI = (params: ProcessMessageType) => {
  if (USE_MOCK) {
    return mockProcessMessage(params).then((data) => data.data);
  }
  return http.put(`${baseUrl}/processMessage`, params);
};
